package com.tanhua.app.controller;

import com.tanhua.app.service.QuanZiService;
import com.tanhua.mongo.Publish;
import com.tanhua.vo.PageBeanVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
public class QuanZiController {

    @Autowired
    private QuanZiService quanZiService;


    @PostMapping(value = "/movements", name = "发布动态")
    public ResponseEntity publishMovements(Publish publish, MultipartFile[] imageContent) throws IOException {

        // 调用service保存
        return quanZiService.publishMovements(publish, imageContent);

    }

    @GetMapping(value = "/movements/all", name = "我的动态")
    public ResponseEntity findAlbumByPage(Integer page, Integer pagesize, Long userId) throws IOException {
        return quanZiService.findAlbumByPage(page, pagesize, userId);
    }

    @GetMapping(value = "/movements", name = "查询好友动态")
    public ResponseEntity findTimeLineByPage(
            @RequestParam(value = "page", defaultValue = "1") Integer page,
            @RequestParam(value = "pagesize", defaultValue = "10") Integer pagesize) {
        return quanZiService.findTimeLineByPage(page, pagesize);
    }

    @GetMapping(value = "/movements/recommend", name = "查看推荐的人动态")
    public ResponseEntity findRecommendPublish(Integer page, Integer pagesize) throws IOException {
        return quanZiService.findRecommendPublish(page, pagesize);
    }

    @GetMapping(value = "/movements/{id}/like", name = "点赞")
    public ResponseEntity likePublish(@PathVariable("id") String publishId) throws IOException {
        quanZiService.toBigDate(2, publishId);
        return quanZiService.likePublish(publishId);
    }

    //取消点赞 -5
    @GetMapping(value = "/movements/{id}/dislike", name = "取消点赞")
    public ResponseEntity unlikePublish(@PathVariable("id") String publishId) throws IOException {
        quanZiService.toBigDate(5, publishId);
        return quanZiService.unlikePublish(publishId);
    }

    //喜欢 +8
    @GetMapping(value = "/movements/{id}/love", name = "动态喜欢")
    public ResponseEntity lovePublish(@PathVariable("id") String publishId) {
        quanZiService.toBigDate(3, publishId);
        return quanZiService.LovePublish(publishId);
    }

    //取消喜欢 -8
    @GetMapping(value = "/movements/{id}/unlove", name = "取消喜欢")
    public ResponseEntity unLovePublish(@PathVariable("id") String publishId) throws IOException {
        quanZiService.toBigDate(6, publishId);
        return quanZiService.unLovePublish(publishId);
    }


    //浏览+1
    @GetMapping(value = "/movements/{publishId}", name = "单条动态(评论内容回显)")
    public ResponseEntity publish(@PathVariable("publishId") String publishId) throws IOException {
        quanZiService.toBigDate(1, publishId);
        return quanZiService.findPublishVoById(publishId);
    }
}